<?php 
include 'init.php';
include 'header.php'; 
?>

			<table>
				<tr><td width="385px" style="text-align: justify">
					<div align="center"><img src="img/bowser.jpg" alt="bowser attacks waluigi" title="bowser attacks waluigi" border=0 /></div><p>
						
					</td>
					<td>&nbsp;</td>
					<td id="login" valign="top" width="223px">
					<span style="font-size:12px"><strong>Password / Passcode Help</strong></span>
					<p />
					<?php					if (!isset($_POST['submit']))					{     					// Show the form     					include 'pass_form.inc.php';     					exit;					}					else					{

					$username = $_POST['username'];					$checkuser = mysql_query("SELECT username FROM user WHERE username='$username'");					$username_exist = mysql_num_rows($checkuser);
					$getcode = mysql_query("SELECT * FROM user WHERE username='$username'");
					$thecode = mysql_fetch_assoc($getcode);
					$thecode = $thecode[passcode];
					$thecode = strtoupper($thecode);
					if($username_exist > 0 && empty($_POST['passcode']))
						{						$to = "w$username@wii.com";						$from = "mii@mariokartchallenger.com";						$subject = "Lost Password Notice";						$message = "It appears your password is lost! To change your password goto the Reset link on the homepage.\n\nYour passcode is : $thecode\n\nIf you didn't reset your password just ignore this message.\n\n-The Mario Kart Challenger Team";						
						mail($to, $subject, $message, "From: $from\r\nReply-to: $from\r\n");   						$pass_error = "Passcode sent to your Wii..";						include 'pass_form.inc.php';						exit;}	
     					else     					{
	     	     				// Check if any of the fields are missing


     							if (empty($_POST['username']))     							{          							// Reshow the form with an error          							$pass_error = 'Please enter your Wii Number...';          							include 'pass_form.inc.php';          							exit;     							}

								if (!is_numeric ($_POST['username']) || strlen($_POST['username']) != 16)								{									$pass_error = 'Your Wii Number is invalid...';          							include 'pass_form.inc.php';          							exit;
								}

     							if ($username_exist == 0)     							{          							// Reshow the form with an error          							$pass_error = 'Wii Number not found..';          							include 'pass_form.inc.php';          							exit;     							}


     					}
	
						if($username_exist > 0 && $thecode == $_POST['passcode'])
						{	
										
						echo '<span style="font-size:10px"><strong>Password reset, Check your Wii</strong></span><p />
Your new temporary password has been sent to your Wii, please update it upon logging in for additional security.<p />
In the meantime, <a href="index.php">click here</a> to go back to the homepage to login.</span><p />';
						$newpass = mt_rand(10000, 99999);						reset_password ($_POST['username'], $newpass);						exit;						}	

					}					?>
					</td>
				</tr>
			</table>
			</td>
		</tr>
	</table>
